home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / MacPerl 5.1.3 / Mac_Perl_513_src / MacPerl5 / MercutioAPI.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-14  |  9.0 KB  |  320 lines  |  [TEXT/MMCC]

  1. /***********************************************************************************
  2. **
  3. **       Developer's Programming Interface for Mercutio Menu Definition Function
  4. **               © 1992-1995 Ramon M. Felciano, All Rights Reserved
  5. **                         Latest C port -- January 17, 1994
  6. **
  7. ************************************************************************************/
  8.  
  9. /*
  10. **    09Aug94 : Tom Emerson
  11. **    Modified by Tom Emerson (tree@bedford.symantec.com) to work correctly with
  12. **    the universal headers, and hence when calling from PowerPC native code.
  13. **    This has been conditionalized so that it will compile with and without the
  14. **  universal interfaces.
  15. **
  16. **    Also cleaned up the code a bit - removed the prototypes from this file and
  17. **    included the header instead. Wrapped the declarations in the header with
  18. **    'extern "C"' when compiling with a C++ compiler.
  19. **
  20. **    
  21. */
  22.  
  23. /*
  24. **    19Dec94 : RMF
  25. **    Updated to full Mercutio 1.2 spec by Ramon Felciano.
  26. **    
  27. **    27Dec94 : RMF
  28. **    MDEF_CalcItemSize now correctly returns a result.
  29. **    MDEF_StripCustomData declares Point at top of function (bug?).
  30. */
  31.  
  32. #include "MercutioAPI.h"
  33.  
  34. #define     _Point2Long(pt)        (* (long *) &pt)        // these would have pbs with register vars
  35. #define     _Long2Point(long)    (* (Point *) &long)
  36.  
  37. //#ifndef __CONDITIONALMACROS__
  38. //typedef pascal void (*MDEFProc)(short msg, MenuHandle theMenu, Rect* menuRect, Point hitPt, short *itemID);
  39. //#endif
  40.  
  41. /***********************************************************************************
  42. **
  43. **   MDEF_GetVersion returns the MDEF version in long form. This can be typecast
  44. **     to a normal version record if needed.
  45. **
  46. ************************************************************************************/
  47. pascal    long    MDEF_GetVersion (MenuHandle menu)
  48. {
  49.     SignedByte state;
  50.     Handle    proc;
  51.     Rect    dummyRect;
  52.     short    dummyInt;
  53.     Point     pt;
  54.     MenuDefUPP    menuProcUPP;
  55.     
  56.     proc = (*menu)->menuProc;    /* same as **menu.menuProc */
  57.     state = HGetState(proc);
  58.     HLock(proc);
  59.     dummyRect.top = dummyRect.left = dummyRect.bottom = dummyRect.right = 0;
  60.  
  61.     SetPt(&pt,0,0);
  62.  
  63.     menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  64.     CallMenuDefProc(menuProcUPP, getVersionMsg, menu, &dummyRect, pt, &dummyInt);    
  65.     DisposeRoutineDescriptor(menuProcUPP);
  66.     
  67.     HSetState(proc, state);
  68.     
  69.     /* the result, a long, is returned in dummyRect.topLeft */
  70.     return _Point2Long(dummyRect);
  71. }
  72.  
  73. /***********************************************************************************
  74. **
  75. **   MDEF_GetCopyright returns a stringHandle to the copyright message for the MDEF.
  76. **
  77. **   IMPORTANT: THE CALLER IS RESPONSIBLE FOR DISPOSING OF THIS HANDLE WHEN DONE
  78. **              WITH IT.
  79. **
  80. ************************************************************************************/
  81. pascal    StringHandle    MDEF_GetCopyright (MenuHandle menu)
  82. {
  83.     SignedByte state;
  84.     Handle    proc;
  85.     Rect    dummyRect;
  86.     short    dummyInt;
  87.     Point     pt;
  88.     MenuDefUPP    menuProcUPP;
  89.     
  90.     proc = (*menu)->menuProc;    /* same as **menu.menuProc */
  91.     state = HGetState(proc);
  92.     HLock(proc);
  93.     dummyRect.top = dummyRect.left = dummyRect.bottom = dummyRect.right = 0;
  94.  
  95.     SetPt(&pt,0,0);
  96.  
  97.     menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  98.     CallMenuDefProc(menuProcUPP, getCopyrightMsg, menu, &dummyRect, pt, &dummyInt);    
  99.     DisposeRoutineDescriptor(menuProcUPP);
  100.  
  101.     HSetState(proc, state);
  102.     
  103.     /* the result, a stringHandle, is returned in dummyRect.topLeft */
  104.     return *(StringHandle*)(&dummyRect);
  105. }
  106.  
  107. /***********************************************************************************
  108. **
  109. **   IsCustomMenu returns true if hMenu is controlled by a custom MDEF. This relies on my}
  110. **   convention of returning the customDefProcSig constant in the rect parameter: this obtuse}
  111. **   convention should be unique enough that only my custom MDEFs behave this way.}
  112. **
  113. ************************************************************************************/
  114. pascal    Boolean MDEF_IsCustomMenu (MenuHandle menu)
  115. {
  116.     SignedByte state;
  117.     Handle    proc;
  118.     Rect    dummyRect;
  119.     short    dummyInt;
  120.     Point     pt;
  121.     MenuDefUPP    menuProcUPP;
  122.     
  123.     proc = (*menu)->menuProc;    /* same as **menu.menuProc */
  124.     state = HGetState(proc);
  125.     HLock(proc);
  126.     dummyRect.top = dummyRect.left = dummyRect.bottom = dummyRect.right = 0;
  127.  
  128.     SetPt(&pt,0,0);
  129.  
  130.     menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  131.     CallMenuDefProc(menuProcUPP, areYouCustomMsg, menu, &dummyRect, pt, &dummyInt);    
  132.     DisposeRoutineDescriptor(menuProcUPP);
  133.  
  134.     HSetState(proc, state);
  135.     
  136.     /* the result, a long, is returned in dummyRect.topLeft */
  137.     return (_Point2Long(dummyRect) == (long) (customDefProcSig));
  138. }
  139.  
  140.  
  141. /***********************************************************************************
  142. **
  143. **   PowerMenuKey is a replacement for the standard toolbox call MenuKey for use with the}
  144. **   Mercutio. Given the keypress message and modifiers parameters from a standard event, it }
  145. **   checks to see if the keypress is a key-equivalent for a particular menuitem. If you are currently}
  146. **   using custom menus (i.e. menus using Mercutio), pass the handle to one of these menus in}
  147. **   hMenu. If you are not using custom menus, pass in NIL or another menu, and PowerMenuKey will use the}
  148. **   standard MenuKey function to interpret the keypress.}
  149. **
  150. **   As with MenuKey, PowerMenuKey returns the menu ID in high word of the result, and the menu}
  151. **   item in the low word.}
  152. **
  153. ************************************************************************************/
  154.  
  155. pascal    long MDEF_MenuKey (long theMessage, short theModifiers, MenuHandle menu)
  156. {
  157.     
  158.     if ((menu == NULL) || (!MDEF_IsCustomMenu(menu))) {
  159.         return(MenuKey((char)(theMessage & charCodeMask)));
  160.     } else {
  161.         Handle proc = (*menu)->menuProc;
  162.         char state = HGetState(proc);
  163.         Rect dummyRect;
  164.         Point pt = _Long2Point(theMessage);
  165.         MenuDefUPP    menuProcUPP;
  166.         
  167.         HLock(proc);
  168.         dummyRect.top = dummyRect.left = 0;
  169.         
  170.         menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  171.         CallMenuDefProc(menuProcUPP, mMenuKeyMsg, menu, &dummyRect, pt, &theModifiers);    
  172.         DisposeRoutineDescriptor(menuProcUPP);
  173.  
  174.         HSetState(proc, state);
  175.         return( _Point2Long(dummyRect));
  176.     }
  177. }
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193. pascal void MDEF_SetCallbackProc (MenuHandle menu, ProcPtr theProc)
  194. {
  195.     Rect    dummyRect;
  196.     short    dummyInt;
  197.     Point     pt;
  198.     MenuDefUPP    menuProcUPP;
  199.  
  200.     Handle proc = (*menu)->menuProc;
  201.     char state = HGetState(proc);
  202.     HLock(proc);
  203.     
  204.     pt.h = (short) (0x0000FFFF & (long) theProc);
  205.     pt.v = (short) ((long) theProc >> 16);
  206.     
  207.     menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  208.     CallMenuDefProc(menuProcUPP, setCallbackMsg, menu, &dummyRect, pt, &dummyInt);    
  209.     DisposeRoutineDescriptor(menuProcUPP);
  210.  
  211.     HSetState(proc, state);
  212. }
  213.  
  214.  
  215.  
  216.  
  217. pascal void MDEF_SetMenuPrefs (MenuHandle menu, MenuPrefsRec *thePrefs)
  218. {
  219.     Rect    dummyRect;
  220.     short    dummyInt;
  221.     Point     pt;
  222.     MenuDefUPP    menuProcUPP;
  223.  
  224.     Handle proc = (*menu)->menuProc;
  225.     char state = HGetState(proc);
  226.     HLock(proc);
  227.  
  228.     pt.h = (short) (0x0000FFFF & (long) thePrefs);
  229.     pt.v = (short) ((long) thePrefs >> 16);
  230.  
  231.     menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  232.     CallMenuDefProc(menuProcUPP, setPrefsMsg, menu, &dummyRect, pt, &dummyInt);    
  233.     DisposeRoutineDescriptor(menuProcUPP);
  234.  
  235.     HSetState(proc, state);
  236. }
  237.  
  238.  
  239.  
  240. pascal void MDEF_StripCustomData (MenuHandle menu)
  241. {
  242.     Rect    dummyRect;
  243.     short    dummyInt;
  244.     MenuDefUPP    menuProcUPP;
  245.  
  246.     Handle proc;
  247.     char state;
  248.     Point     pt;
  249.     
  250.     proc = (*menu)->menuProc;
  251.     state = HGetState(proc);
  252.     HLock(proc);
  253.  
  254.  
  255.     menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  256.     CallMenuDefProc(menuProcUPP, stripCustomDataMsg, menu, &dummyRect, pt, &dummyInt);    
  257.     DisposeRoutineDescriptor(menuProcUPP);
  258.  
  259.     HSetState(proc, state);
  260. }
  261.  
  262.  
  263.  
  264.  
  265. pascal void MDEF_DrawItem (MenuHandle menu, short item, Rect destRect)
  266. {
  267.     short    dummyInt;
  268.     Point     pt = {0,0};
  269.     MenuDefUPP    menuProcUPP;
  270.  
  271.     Handle proc = (*menu)->menuProc;
  272.     char state = HGetState(proc);
  273.     HLock(proc);
  274.  
  275.     menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  276.     CallMenuDefProc(menuProcUPP, mDrawItemMsg, menu, &destRect, pt, &dummyInt);    
  277.     DisposeRoutineDescriptor(menuProcUPP);
  278.  
  279.     HSetState(proc, state);
  280. }
  281.  
  282.  
  283. pascal void MDEF_DrawItemState (MenuHandle menu, short item, Rect destRect, Boolean isHilited, Boolean isEnabled)
  284. {
  285.     Point    pt;
  286.     MenuDefUPP    menuProcUPP;
  287.  
  288.     Handle proc = (*menu)->menuProc;
  289.     char state = HGetState(proc);
  290.     HLock(proc);
  291.  
  292.     pt.h = (short) isHilited;
  293.     pt.v = (short) isEnabled;
  294.  
  295.     menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  296.     CallMenuDefProc(menuProcUPP, mDrawItemStateMsg, menu, &destRect, pt, &item);    
  297.     DisposeRoutineDescriptor(menuProcUPP);
  298.  
  299.     HSetState(proc, state);
  300. }
  301.  
  302.  
  303. pascal void MDEF_CalcItemSize (MenuHandle menu, short item, Rect *destRect)
  304. {
  305.     Point     pt = {0,0};
  306.     MenuDefUPP    menuProcUPP;
  307.  
  308.     Handle proc = (*menu)->menuProc;
  309.     char state = HGetState(proc);
  310.     HLock(proc);
  311.  
  312.     menuProcUPP = (MenuDefUPP)NewRoutineDescriptor((ProcPtr)*proc, uppMenuDefProcInfo, kM68kISA);
  313.     CallMenuDefProc(menuProcUPP, mCalcItemMsg, menu, destRect, pt, &item);    
  314.     DisposeRoutineDescriptor(menuProcUPP);
  315.  
  316.     HSetState(proc, state);
  317. }
  318.  
  319.  
  320.